package com.xinxin.leetcode.problem669;

import com.xinxin.leetcode.common.TreeNode;

/**
 * @author ShiXinXin
 * @date 2020-02-17 23:57
 */
public class Solution {
    public TreeNode trimBST(TreeNode root, int L, int R) {
        if (root == null) {
            return null;
        }
        if (root.val < L) {
            return trimBST(root.right, L, R);
        } else if (root.val > R) {
            return trimBST(root.left, L, R);
        } else {
            root.left = trimBST(root.left, L, root.val);
            root.right = trimBST(root.right, root.val, R);
            return root;
        }
    }

    public static void main(String[] args) {

    }
}
